﻿using HuaweiCloud.Dotnet.Samples.ESports.Dbs;
using HuaweiCloud.Dotnet.Samples.ESports.Entities;
using HuaweiCloud.Dotnet.Samples.ESports.Services;
using Microsoft.AspNetCore.Mvc;


namespace HuaweiCloud.Dotnet.Samples.ESports.ApiControllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class StepController : ControllerBase
    {
        private readonly IStepAppService _service;
        public StepController(IStepAppService service)
        {
            _service = service;
        }

        // 获取实体列表
        // GET: api/Step
        [HttpGet]
        public async Task<IEnumerable<Step>> Get()
        {
            return await _service.ListAsync();
        }

        // 获取指定Id的实体详情
        // GET api/Step/{id}
        [HttpGet("{id}")]
        public async Task<Step> Get(int id)
        {
            return await _service.GetAsync(id);
        }
        // 新建实体
        // POST api/Step
        [HttpPost]
        public async Task Post([FromBody] Step input)
        {
            await _service.AddAsync(input);
        }

        // 更新指定id的实体
        // PUT api/Step/{id}
        [HttpPut("{id}")]
        public async Task Put(int id, [FromBody] Step input)
        {
            input.Id = id;
            await _service.UpdateAsync(input);
        }

        // 删除指定id的实体
        // DELETE api/Step/{id}
        [HttpDelete("{id}")]
        public async Task Delete(int id)
        {
            await _service.DeleteAsync(id);
        }
    }
}
